package com.yadong.smarthome2.ui;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yadong.smarthome2.protocol2.ResultProtocol.DeviceInfo.Status;

public class StatusListAdapter extends BaseAdapter {
    private LayoutInflater mLayoutInflater;
    public StatusListAdapter(Context context) {
        mLayoutInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    private List<Status> mStatuses = new ArrayList<Status>();

    public void setStatus(List<Status> functions) {
        this.mStatuses = functions;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mStatuses.size();
    }

    @Override
    public Object getItem(int position) {
        return mStatuses.get(position);
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = mLayoutInflater.inflate(
                    android.R.layout.simple_list_item_1, viewGroup, false);
        }
        Status status = mStatuses.get(position);
        TextView textView = ((TextView) view.findViewById(android.R.id.text1));
        textView.setText(status.getName());
        return view;
    }
}